clear all
use "~/Desktop/QJPS Replication/Table_1.dta", clear

bys year: gen UK = cscore if cow == 200
sort year UK
carryforward UK, gen(UK2)
gen dist_UK = abs(cscore - UK2)
drop UK UK2

bys cow: egen distance_UK = mean(dist_UK)
drop dist_UK

bys year: gen FR = cscore if cow == 220
sort year FR
carryforward FR, gen(FR2)
gen dist_FR = abs(cscore - FR2)
drop FR FR2

bys cow: egen distance_FR = mean(dist_FR)
drop dist_FR

bys year: gen SP = cscore if cow == 230
sort year SP
carryforward SP, gen(SP2)
gen dist_SP = abs(cscore - SP2)
drop SP SP2

bys cow: egen distance_SP = mean(dist_SP)
drop dist_SP

sort cow year
bys cow: gen n = _n == 1
drop if n != 1

gen colony = 4
*none
replace colony = 0 if ht_colonial == 0
*UK
replace colony = 1 if ht_colonial == 5
*FR
replace colony = 2 if ht_colonial == 6
*SP
replace colony = 3 if ht_colonial == 2

set seed 4227492
bootstrap, reps(1000): sureg (distance_UK i.colony if cow != 200 & cow != 220 & cow != 230) (distance_FR i.colony) (distance_SP i.colony)
